import pickle

def getAdaboostImportance(adaboost, Xcols):
    # 获取每个基分类器的权重
    classifier_weights = adaboost.estimator_weights_

    # 获取每个基分类器的实例
    classifiers = adaboost.estimators_

    # 获取特征对输出的贡献度
    feature_importances = {}
    for i, classifier in enumerate(classifiers):
        for j, feature in enumerate(Xcols):
            if feature not in feature_importances:
                feature_importances[feature] = 0
            feature_importances[feature] += classifier_weights[i] * classifier.feature_importances_[j]

    print('各个特征贡献度')
    feature_importances = feature_importances.items()
    feature_importances = sorted(feature_importances, key=lambda d: d[1], reverse=True)
    for feature, importance in feature_importances:
        print(f"{feature}: {importance}")
    return feature_importances

def loadModel(path):
    f = open(path, 'rb')
    model = pickle.load(f)
    f.close()
    return model